package org.thingsboard.server.schedule.core;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.thingsboard.server.common.data.SchedulerEvent;
import org.thingsboard.server.common.data.SchedulerEventInfo;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.dao.schedulerEvent.SchedulerEventService;
import org.thingsboard.server.service.schedule.ScheduleService;
import org.thingsboard.server.utils.SpringUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


@Slf4j
public  class DefaultJobHandler implements Job {
    public static final String JOB_KEY = "TASK_KEY";
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        SchedulerEventInfo schedulerEventInfo= (SchedulerEventInfo) context.getJobDetail().getJobDataMap().get(JOB_KEY);
        ScheduleService service=SpringUtil.getBean(ScheduleService.class);
        SchedulerEventService schedulerEventService= SpringUtil.getBean(SchedulerEventService.class);
        SchedulerEvent schedulerEvent=  schedulerEventService.findSchedulerEventById(schedulerEventInfo.getId());
        service.executeHandler(schedulerEvent);
    }
}
